package com.elite;

import java.io.FileInputStream;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class FtpServlet extends HttpServlet{
	private static final Log log=LogFactory.getLog(FtpServlet.class);
	private FileFTP fileftp; 
	private Thread t; 
	public void destroy() {
		log.info("服务器关闭!");
	}
	
	public void init(){
		log.info("-------------FtpServlet Start----------------");
		
		try{
			fileftp = new FileFTP();
			fileftp.setIp(this.getInitParameter("IP"));
			fileftp.setPort(this.getInitParameter("PORT"));
			fileftp.setUsername(this.getInitParameter("USERNAME"));
			fileftp.setPassword(this.getInitParameter("PASSWORD"));
			fileftp.setDotime(this.getInitParameter("DOTIME"));
			fileftp.setFilename(this.getInitParameter("FILENAME"));
			fileftp.setSqlname(this.getInitParameter("SQLNAME"));
			fileftp.setResult(this.getInitParameter("RESULT"));		
			fileftp.setSqlname1(this.getInitParameter("SQLNAME1"));	
		}catch(Exception e){
			log.info("获取XML参数出错:"+e);
		}
		
		try{
	        ServletContext application;   
	        WebApplicationContext wac;   
	        application = getServletContext();   
	        wac = WebApplicationContextUtils.getWebApplicationContext(application);//获取spring的context  
	        com.elite.FtpBean ftpbean = (com.elite.FtpBean) wac.getBean("ftpbean");  
	        fileftp.setFtpbean(ftpbean);
	    	t = new Thread(fileftp); 
	        t.start(); //   启动FTP批量上传线程 				
		}catch(Exception e){
			log.info("启动FTP批量上传线程出错:"+e);
		}
        log.info("启动FTP批量上传线程 ");

	}

}
